﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Markup;
using System.Windows.Media.Imaging;

namespace WPF.TreeView
{
    internal class RelativeImagePathToBitmapConverter : MarkupExtension, IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string resourceLocation = value.ToString();
            Uri uri = new Uri(resourceLocation, UriKind.Relative);
            BitmapImage bitmapImage = new BitmapImage(uri);

            return bitmapImage;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return new RelativeImagePathToBitmapConverter();
        }
    }
}
